﻿/************************************************************************
 * CoreDES - A small and core library for discrete event systems
 * Copyright (C) 2012-2013 Ali Khalili (khalili_DOT_ir_@SIGN_gmail_DOT_com)
 * **********************************************************************
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License (LGPL) published 
 * by the Free Software Foundation; either version 2.1 of the License, or (at your
 * option) any later version. This program is distributed without any
 * warranty. See the GNU Lesser General Public License for more details. 
 * ***********************************************************************
 * File         :     CoreDES\Utils\ListEnumerator.cs
 * Description  :     List enumarator class to be used for enumaration of a list within type T
 * Change log   :     -10 Dec 2011: initial version
 * To Do        :
 ************************************************************************/
using System;
using System.Collections.Generic;
using System.Collections;

namespace CoreDES.Utils
{
    /// <summary>
    /// List enumarator class to be used for enumaration of a list within type T
    /// </summary>
    /// <typeparam name="T">Type of objects in the list</typeparam>
    public class ListEnumerator<T> : IEnumerator
    {
        private int position = -1;
        List<T> list;

        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="list">the list to be enumerated</param>
        public ListEnumerator(List<T> list)
        {
            this.list = list;
        }

        /// <summary>
        /// Declare the MoveNext method required by IEnumerator:
        /// </summary>
        /// <returns></returns>
        public bool MoveNext()
        {
            if (position < list.Count - 1)
            {
                position++;
                return true;
            }
            else
            {
                return false;
            }
        }

        /// <summary>
        /// Declare the Reset method required by IEnumerator:
        /// </summary>
        public void Reset()
        {
            position = -1;
        }

        /// <summary>
        /// Declare the Current property required by IEnumerator
        /// </summary>
        public object Current
        {
            get
            {
                return list[position];
            }
        }
    }
}
